

#include <cegfx/cepostprocessrenderer.h>


cePostProcessRenderer::cePostProcessRenderer (LPDIRECT3DDEVICE9 device)
	: device (device)
{
	vertices[0] = Vertex (-1, -1, 0, 0, 1);
	vertices[1] = Vertex ( 1, -1, 0, 1, 1);
	vertices[2] = Vertex (-1,  1, 0, 0, 0);
	vertices[3] = Vertex ( 1,  1, 0, 1, 0);

	indices[0] = 0;
	indices[1] = 3;
	indices[2] = 1;

	indices[3] = 0;
	indices[4] = 2;
	indices[5] = 3;
}

void cePostProcessRenderer::Init2D (const iViewport* viewport)
{
	D3DXMatrixOrthoOffCenterLH (&proj, 0, 1, 0, 1, -1, 1);
}

float get_random ()
{
	return (float)rand () / (float)RAND_MAX;
}

void cePostProcessRenderer::RenderFSQuad (LPDIRECT3DTEXTURE9 texture, ceEffect* effect, LPDIRECT3DTEXTURE9 effectTxt)
{
	D3DXHANDLE handle = effect->GetHandleBySemantic ("EFFECT0");

	D3DXVECTOR4 disp (get_random(), get_random(), 0, 0);

	effect->Begin ();
	effect->BeginPass (0);
	effect->SetDiffuseTexture (texture);
	effect->SetEffect0Texture (effectTxt);
	effect->SetVector (handle, &disp);
	effect->GetEffect ()->CommitChanges();

	device->SetFVF (D3DFVF_XYZ | D3DFVF_TEX1);
	device->DrawIndexedPrimitiveUP (D3DPT_TRIANGLELIST, 0, 4, 2, (const void*)indices, D3DFMT_INDEX16, (const void*)vertices, sizeof (Vertex));

	effect->EndPass ();
	effect->End ();
}

